import datetime
import time
def register_function_used_time(f):
    """计算函数运行时间的装饰器"""
    def func(*args,**kwargs):
        before=datetime.datetime.now()
        f(*args,**kwargs)
        after = datetime.datetime.now()
        used_time=after-before
        print("the function：{} used time:{}".format(f.__name__,used_time))
    return func

@register_function_used_time
def test_func():
    time.sleep(10)
    print("func is running")


if __name__=="__main__":
    test_func()